<!-- xml version="1.0" encoding="utf-8" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
	<title>Greek Vocabulary</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<link href="../classics.css" rel="stylesheet" type="text/css">
</head>
<?php

try {
	$db = new PDO('sqlite:exercise.db3');
	$q = $db->query('SELECT DISTINCT book FROM vocabulary ORDER BY book;');
	$books = array();
	foreach( $q->fetchAll() as $row) {
		$books[$row['book']] = array();
	}
	
	foreach($books as $book => $abk) {
		$q = $db->query("SELECT DISTINCT unit FROM vocabulary WHERE book=$book ORDER BY unit;");
		foreach( $q->fetchAll() as $row) {
			$books[$book][] = $row['unit'];
		}
	}

	$db = NULL;
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
?>


<body>


<div id="container">
<div id="center">
<form name="v01" action="VocFlash.php" method="post">
<table align="center">
<caption>Greek Vocabulary</caption>
<?php
	foreach($books as $book => $abk) {
		print "<tr><th colspan=10 class=\"separate-above\">Book $book</th></tr>\n";
		$n = 0;
		print "<tr>";
		foreach($abk as $unit) {
			print "<td><input type=\"checkbox\" name=\"units[]\" value=\"$book.$unit\" />$unit</td>";
			$n++;
			if (! ($n % 10)) {
				print "</tr>\n<tr>";
			}
		}
		print "</tr>\n";
	}
?>
<tr class="separate-above">
	<td align="center" colspan=10><input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
</div>
</div>

</body>
</html>
